<?php

class Address_model extends CI_Model {
    
    public function getSum($table,$where){
        $query = $this->db->select('id')->where($where)->get($table);
        return count($query->result_array());
    }
    
    
    //获取发件人信息列表
    public function addressInfo($table,$where,$page=0,$limit=10){
        $query = $this->db->select('*')->where($where)->limit($limit, $page)->get($table);
        return $query->result_array();
    }
    
    //获取发件人信息列表
    public function receiveraddressInfo($where,$page=0,$limit=10){
        $query = $this->db->select('su_receiver.*,su_group.name')->where($where)->join('su_group', 'su_receiver.group_id=su_group.id', 'left')->limit($limit,$page)->get('su_receiver');
        return $query->result_array();
    }
    //获取收件人信息列表
    public function senderaddressInfo($type=1,$table,$where,$page=0,$limit=10){
        $query = $this->db->select('*')->where($where)->limit($limit, $page)->get($table);
        return $query->result_array();
    }
    
    
    
    

    //批量插入收件人/发件人信息数据
    public function insertAddress($table,$address){
        $this->db->insert_batch($table,$address);
        return $this->db->affected_rows()?true:false;
    }
    
    
    //单条插入收件人/发件人信息数据
    public function insertAddressHandy($table,$address){
        $this->db->insert($table,$address);
        return $this->db->affected_rows()?true:false;
    }
    
    //查询是否有重复数据
    public function checkAddress($table,$where){
        $query = $this->db->select('id')->where($where)->get($table);
        return $query->result_array();
    }
    
    public function getAddress($table,$where){
        $query = $this->db->where($where)->get($table);
        return $query->row_array();
    }
    
    public function updateAddress($table,$where,$data){
        $this->db->where($where)->update($table,$data);
        return $this->db->affected_rows()?true:false;
    }
    
    //删除数据
    public function delAddress($table,$where){
        $state = $this->db->where_in('id', $where)->delete($table);
        return $state;
    }
            
    
    
    

}
